package com.egao.orderB.controller;

import com.egao.common.core.annotation.ApiPageParam;
import com.egao.common.core.damon.results.PageResult2;
import com.egao.common.core.web.*;
import com.egao.common.core.annotation.OperLog;
import com.egao.orderB.entity.Customer;
import com.egao.orderB.service.CustomerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.ui.Model;


/**
 *
 * 客户管理
 * @author : Doman
 * @date : 2021-12-21 15:17:37
 * @version ：1.0
 */

@Api(tags = "客户管理")
@RestController
@RequestMapping("/api/orderB/customer")
public class CustomerController extends BaseController {

	@Autowired
	private CustomerService customerService;

	/**
	 * 分页查询列表
	 */
	@PreAuthorize("hasAuthority('orderB:customer:list')")
  @ApiOperation(value ="分页查询客户管理",notes = "" +
    "limit:每页显示几行 必填\n" +
    "page:第几页 必填\n" +
    "name:客户名称\n" +
    " \n\n\n" +
    "返回的结果:\n" +
    "id:id\n" +
    "name:客户名称\n" +
    "abbreviation:客户名称缩写\n" +
//    "profilePicture:头像\n" +
//    "pinyin:客户名称拼音\n" +
//    "code:客户代码\n" +
    "account:账号\n" +
    "socialCode:统一社会信用代码\n" +
    "businessLicense:营业执照图片\n" +
    "agreement:合同\n" +
    "agreementStart:合同开始时间\n" +
    "agreementEnd:合同结束时间\n" +
    "settle:结算周期周结,月结\n" +
    "contacts:联系人\n" +
    "contactsPhone:联系人电话\n" +
    "salesmanid:业务员Id\n" +
    "salesman:业务员\n" +
    "operaterid:操作Id\n" +
    "operater:操作\n" +
    "address:公司地址\n" +
    "invoiceState:是否开票:开票1 不开票0\n" +
    "registerDate:注册时间\n" +
    "type:客户类型:车队,货代\n" +
    "state:审核状态: 未审核,已审核\n" +
    "message:是否发送短信 1发送 0不发送\n" +
    "gzhSend:是否发送公众号 1发送 0不发送\n" +
//    "offerLimitNum:客户下单数量限制\n" +
//    "orderNum:排序\n" +
    "createTime:创建时间\n" +
    "createUser:创建人\n" +
    "updateTime:更新时间\n" +
    "updateUser:更新人\n" +
    "",httpMethod = "POST")
  @ApiPageParam
  @PostMapping("/list")
  public JsonResult page(PageResult2<T> page, Customer customer) throws Exception{
    return customerService.list(page, customer, getLoginUser());
  }

  /**
   * 查询全部客户管理
   */
  @PreAuthorize("hasAuthority('orderB:customer:list')")
  @ApiOperation("查询全部客户管理")
  @PostMapping("/listAll")
  public JsonResult list(Customer customer){
    return customerService.list(customer, getLoginUser());
  }

  /**
   * 根据id查询客户管理
   */
  @PreAuthorize("hasAuthority('orderB:customer:list')")
  @ApiOperation("根据id查询客户管理")
  @PostMapping("/get")
  public JsonResult get(Customer customer) {
    return customerService.getById(customer);
  }


  /**
   * 添加客户管理
   */
  @PreAuthorize("hasAuthority('orderB:customer:save')")
  @OperLog(value = "客户管理", desc = "添加", param = false, result = true)
  @ApiOperation(value ="添加客户管理",notes = "" +
    "name:客户名称\n" +
    "abbreviation:客户名称缩写\n" +
//    "profilePicture:头像\n" +
//    "pinyin:客户名称拼音\n" +
//    "code:客户代码\n" +
    "account:账号\n" +
    "socialCode:统一社会信用代码\n" +
    "businessLicense:营业执照图片\n" +
    "agreement:合同\n" +
    "agreementStart:合同开始时间\n" +
    "agreementEnd:合同结束时间\n" +
    "settle:结算周期周结,月结\n" +
    "contacts:联系人\n" +
    "contactsPhone:联系人电话\n" +
    "salesmanid:业务员Id\n" +
    "salesman:业务员\n" +
    "operaterid:操作Id\n" +
    "operater:操作\n" +
    "address:公司地址\n" +
    "invoiceState:是否开票:开票1 不开票0\n" +
    "registerDate:注册时间\n" +
    "type:客户类型:车队,货代\n" +
    "state:审核状态: 未审核,已审核\n" +
    "message:是否发送短信 1发送 0不发送\n" +
    "gzhSend:是否发送公众号 1发送 0不发送\n" +
//    "offerLimitNum:客户下单数量限制\n" +
//    "orderNum:排序\n" +
    "",httpMethod = "POST")
  @PostMapping("/save")
  public JsonResult save(Model model, Customer customer) {
    return customerService.save(customer, getLoginUser());
  }

  /**
   * 修改客户管理
   */
  @PreAuthorize("hasAuthority('orderB:customer:update')")
  @OperLog(value = "客户管理", desc = "修改", param = false, result = true)
  @ApiOperation(value ="修改客户管理",notes = "" +
    "id:id\n" +
    "name:客户名称\n" +
    "abbreviation:客户名称缩写\n" +
//    "profilePicture:头像\n" +
//    "pinyin:客户名称拼音\n" +
//    "code:客户代码\n" +
    "account:账号\n" +
    "socialCode:统一社会信用代码\n" +
    "businessLicense:营业执照图片\n" +
    "agreement:合同\n" +
    "agreementStart:合同开始时间\n" +
    "agreementEnd:合同结束时间\n" +
    "settle:结算周期周结,月结\n" +
    "contacts:联系人\n" +
    "contactsPhone:联系人电话\n" +
    "salesmanid:业务员Id\n" +
    "salesman:业务员\n" +
    "operaterid:操作Id\n" +
    "operater:操作\n" +
    "address:公司地址\n" +
    "invoiceState:是否开票:开票1 不开票0\n" +
    "registerDate:注册时间\n" +
    "type:客户类型:车队,货代\n" +
    "state:审核状态: 未审核,已审核\n" +
    "message:是否发送短信 1发送 0不发送\n" +
    "gzhSend:是否发送公众号 1发送 0不发送\n" +
//    "offerLimitNum:客户下单数量限制\n" +
//    "orderNum:排序\n" +
    "",httpMethod = "POST")
  @PostMapping("/update")
  public JsonResult update(Model model, Customer customer) {
    return customerService.update(customer, getLoginUser());
  }

  /**
   * 删除客户管理
   */
  @PreAuthorize("hasAuthority('orderB:customer:remove')")
  @OperLog(value = "客户管理", desc = "删除", result = true)
  @ApiOperation(value ="删除客户管理",notes = "" +
    "id:id\n" +
    "",httpMethod = "POST")
  @PostMapping("/remove")
  public JsonResult remove(Customer customer ) {
    return customerService.remove(customer, getLoginUser());
  }

}
